<?php

namespace backend\models;

use Yii;
use common\models\UserInfo;
use yii\helpers\ArrayHelper;
use yii\db\ActiveRecord;
use backend\models\Qr;
use backend\models\PayTrade;

class AfterService extends \yii\db\ActiveRecord
{
    public $trade_class;//订单类别  1普通订单  2众筹订单
	public $address;
 
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'afterservice_order';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {    	
        return [
            [['id', 'status','createtime','updatetime','update_uid','create_uid'], 'integer'],
            [['username','phone','customer_service'], 'string', 'max' => 20],
            [['trade_no','contact_time'], 'string'],
            [[ 'username','phone','trade_no'],'required'],
            ['status','default','value'=>0],
        // 临时取消订单号唯一验证	[['trade_no'], 'exist','targetClass' => '\backend\models\PayTrade', 'message' => '订单编号不存在!'],
            [['updatetime','remark','customer_service','content','insert_content','process_content'],'safe'],
        ];
    }
    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'trade_class' => '订单类别',
            'status' => Yii::t('app','状态'),
            'content' => Yii::t('app','内容'),
            'username' => Yii::t('app','用户名'),
            'phone' => Yii::t('app','联系方式'),
            'createtime' => Yii::t('app','创建时间'),
            'contact_time' => Yii::t('app','联系时间'),
            'trade_no' => Yii::t('app','订单编号'),
            'customer_service' => Yii::t('app','客服'),
            'remark' => Yii::t('app','备注'),
            'updatetime' => Yii::t('app','修改时间'),
        	'insert_content'=>Yii::t('app','补充描述'),
        	'process_content'=>Yii::t('app','处理详情'),
        		'insert_procontent'=>Yii::t('app','补充处理详情')
        ];
    }

    public function getPayTrade() 
    {
    	return $this->hasOne(PayTrade::className(),['trade_no'=>'trade_no']);
    }
   /**
    * 判断订单是否真实存在
    */
    public function CheckTradeno($tradeno){
    	$trade=PayTrade::find()->where(['=','trade_no',$tradeno])->exists();
    	if($trade){
    		return true;
    	}else{
    		return false;
    	}
    }
}
